import { Injectable, UnauthorizedException } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';

@Injectable()
export class JwtAuthGuard extends AuthGuard('jwt') {
  handleRequest(err, user, info) {
    if (err || !user) {
      const errorMessage = info ? info.message : '未知认证错误';
      console.error('JWT 认证失败:', errorMessage);
      throw err || new UnauthorizedException(errorMessage);
    }
    return user;
  }
}